Let’s fetch some data:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from pandas_datareader import wb
sns.set(style = "whitegrid", rc = {"figure.figsize": (10, 8)})
eu_countries = ['BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES', 'FR', 'HR',
'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'AT', 'PL', 'PT',
'RO', 'SI', 'SK', 'FI', 'SE', 'GB']
ue = wb.download(indicator = "SL.UEM.TOTL.ZS",
country = eu_countries, start = 1991,
end = 2019)
ue.reset_index(inplace = True)
ue.columns = ['country', 'year', 'unemployment']seabornseaborn’s heatmap() function; takes a wide data frame with x-values in the index and y-values as column headersseaborn ‘heat map’seabornseabornseaborncolor_palette() function, can be viewed with the palplot() function, and reversed by adding _rseaborncolor_palette() also allows for the creation of custom palettes!colors = ['#F5A422', '#3E22F5', '#3BF522',
'#C722F5', '#F53E22']
pal = sns.color_palette(colors)
sns.palplot(pal)seabornmx = pd.read_csv('http://personal.tcu.edu/kylewalker/mexico.csv')
sns.barplot(x = 'gdp08', y = 'name',
data = mx.sort_values('gdp08', ascending = False),
palette = "Greens_r")# Convert the year to integer for better labels
ue["year"] = ue["year"].astype(int)
# Create a recoded column where all values are "Other" besides Greece
ue["country2"] = ue.country.where(ue.country == "Greece", "Other")
# Sort on the recoded column to plot Greece last
ue.sort_values("country2", ascending = False, inplace = True)seaborn is a wrapper around matplotlib, the main plotting engine for Pythonmatplotlib customization methods are available for your seaborn plots - and there are many!import matplotlib.pyplot as pltseaborn and matplotlibseaborn returns a matplotlib object that can be modified by the options in the pyplot moduleseaborn and available as arguments - so check the documentation to see what you can do!